package com.fjxd.planeTicket.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjxd.feign.clients.CityClient;
import com.fjxd.feign.clients.FlightNumberClient;
import com.fjxd.feign.clients.TicketStoreClient;
import com.fjxd.feign.pojo.FlightNumber;
import com.fjxd.feign.pojo.Plane;
import com.fjxd.feign.pojo.TicketStore;
import com.fjxd.planeTicket.mapper.PlaneTicketMapper;
import com.fjxd.planeTicket.pojo.Ticket;
import com.fjxd.planeTicket.service.PlaneTicketService;
import com.fjxd.planeTicket.vo.TicketVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author csw
 */
@Service
public class PlaneTicketServiceImpl extends ServiceImpl<PlaneTicketMapper, Ticket> implements PlaneTicketService {
    final PlaneTicketMapper planeTicketMapper;

    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private TicketStoreClient ticketStoreClient;
    @Autowired
    private FlightNumberClient flightNumberClient;
    @Autowired
    private CityClient cityClient;

    public PlaneTicketServiceImpl(PlaneTicketMapper planeTicketMapper) {
        this.planeTicketMapper = planeTicketMapper;
    }

    @Override
    public List<Ticket> getTicketFlightNumberId(Integer fId) {

        return planeTicketMapper.getTicketFlightNumberId(fId);
    }

    @Override
    public Ticket getTicketByFlightNumberId(Integer fId, String startDate) {
        List<String> cities = new ArrayList<>();
        FlightNumber flightNumberById = flightNumberClient.getFlightNumberById(fId);
        cities.add(flightNumberById.getUpAirportName());
        cities.add(flightNumberById.getDownAirportName());
        Ticket value = planeTicketMapper.getTicketByFlightNumberId(fId, startDate);
        value.setUpAirportName(flightNumberById.getUpAirportName());
        value.setDownAirportName(flightNumberById.getDownAirportName());
        List<TicketStore> ticketStoreList = ticketStoreClient.getTicketStoreList(value.getId());
//        value.setAlignName(cities);
        value.setTicketStores(ticketStoreList);
        return value;
    }

    @Override
    public Ticket getPlaneByFid(Integer fid) {
        return planeTicketMapper.getPlaneByFid(fid);
    }


}
